package com.lu.statistics.common.config;

import cn.dev33.satoken.stp.StpInterface;
import com.lu.statistics.entity.SysAppUser;
import com.lu.statistics.mapper.SysAppUserMapper;
import com.lu.statistics.mapper.TbUserMapper;
import com.lu.statistics.service.AppUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@Component
public class StpInterfaceImpl implements StpInterface {
    @Autowired
    private AppUserService userService;

    /**
     * 返回一个用户所拥有的权限集合
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginKey) {
        int userId = Integer.parseInt(loginId.toString());
        // 本 list 仅做模拟，实际项目中要根据具体业务逻辑来查询权限
        Set<String> permissions = userService.queryUserPermCodeListByUser(userId);
        ArrayList list = new ArrayList();
        list.addAll(permissions);
        return list;
    }

    /**
     * 返回一个用户所拥有的角色标识集合
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginKey) {
        //因为本项目不需要用到角色判定，所以这里就返回一个空的ArrayList对象
        List<String> list = new ArrayList<String>();
        list.add("admin");
        list.add("super-admin");
        return list;
    }
}
